home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 187_01 / sub_str.c < prev    next >
C/C++ Source or Header  |  1985-12-29  |  1KB  |  40 lines

  1. /*@*****************************************************/
  2. /*@                                                    */
  3. /*@ sub_str - search a string for a given substring.   */
  4. /*@        Uses INDEX to find occurance of first       */
  5. /*@        char of substring, then STRCMP to check     */
  6. /*@        the rest for a match.                       */
  7. /*@                                                    */
  8. /*@   Usage:     sub_str(search, find);                */
  9. /*@       where search is the string to search.        */
  10. /*@             find is the substring for which to     */
  11. /*@                  search.                           */
  12. /*@                                                    */
  13. /*@   Returns TRUE if the substring is found,          */
  14. /*@           FALSE otherwise.                         */
  15. /*@                                                    */
  16. /*@*****************************************************/
  17.  
  18. #define        TRUE    1
  19. #define        FALSE    0
  20.  
  21. int sub_str(ss, sf)
  22. char *ss, *sf;
  23. {
  24.     int len;
  25.     char *index(), *k;
  26.  
  27.     len = strlen(sf);
  28.     k = ss;
  29.     while (k) {
  30.         if (k = index(k, *sf))
  31.             if (!strncmp(k, sf, len))
  32.                 return TRUE;
  33.             else
  34.                 k++;
  35.     }
  36.  
  37.     return FALSE;
  38.  
  39. }
  40.